package com.dongdongshop.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dongdongshop.data.Page;
import com.dongdongshop.data.Result;
import com.dongdongshop.em.ResultEnum;
import com.dongdongshop.pojo.TbContentCategory;
import com.dongdongshop.pojo.TbGoods;
import com.dongdongshop.service.ContentCateGoryService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("contentCateGory")
public class ContentCateGoryController {

    @Reference
    private ContentCateGoryService contentCateGoryService;

    @RequestMapping("show")
    public String show(){
        return "admin/content_category";
    }

    @RequestMapping("contentCatGoryList")
    @ResponseBody
    public Result contentCatGoryList(@RequestParam("name")String name){
        try {
            List<TbContentCategory> contentCatGoryList = contentCateGoryService.contentCatGoryList(name);
            return Result.response(ResultEnum.SUCCESS).setData(contentCatGoryList);
        } catch (Exception e) {
            return Result.response(ResultEnum.ERROR).setData(e);
        }
    }

    @RequestMapping("addContentCatGory")
    @ResponseBody
    public Result addContentCatGory(TbContentCategory tbContentCategory){
        try {
            Integer i = contentCateGoryService.addContentCatGory(tbContentCategory);
            return Result.response(ResultEnum.SUCCESS).setData(i);
        } catch (Exception e) {
            return Result.response(ResultEnum.ERROR).setData(e);
        }
    }

    @RequestMapping("getContentCatGoryById")
    @ResponseBody
    public Result getContentCatGoryById(Long id){
        try {
            TbContentCategory i = contentCateGoryService.getContentCatGoryById(id);
            return Result.response(ResultEnum.SUCCESS).setData(i);
        } catch (Exception e) {
            return Result.response(ResultEnum.ERROR).setData(e);
        }
    }

    @RequestMapping("updateContentCatGory")
    @ResponseBody
    public Result updateContentCatGory(TbContentCategory tbContentCategory){
        try {
            Integer i = contentCateGoryService.updateContentCatGory(tbContentCategory);
            return Result.response(ResultEnum.SUCCESS).setData(i);
        } catch (Exception e) {
            return Result.response(ResultEnum.ERROR).setData(e);
        }
    }

    @RequestMapping("deleteContentCatGory")
    @ResponseBody
    public Result deleteContentCatGory(@RequestParam("id[]") Long[] id){
        try {
            Integer i = contentCateGoryService.deleteContentCatGory(id);
            return Result.response(ResultEnum.SUCCESS).setData(i);
        } catch (Exception e) {
            return Result.response(ResultEnum.ERROR).setData(e);
        }
    }
}
